// SensitiveCheckController.java
package com.acane.instagram.controller;

import com.acane.instagram.pojo.Result;
import com.acane.instagram.pojo.dto.SensitiveCheckRequest;
import com.acane.instagram.service.SensitiveWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sensitive")
public class SensitiveCheckController {

    @Autowired
    private SensitiveWordService sensitiveWordService;

    @PostMapping("/check")
    public Result checkSensitiveText(@RequestBody SensitiveCheckRequest request) {
        // 参数校验
        if (request == null || request.getText() == null || request.getText().trim().isEmpty()) {
            return Result.failure(400, "检测文本不能为空");
        }

        // 执行敏感词检测
        boolean hasSensitive = sensitiveWordService.containsSensitive(request.getText());
        return Result.success(hasSensitive); // 自动匹配success(Object data)方法
    }
}